package com.kclm.se.jcf;

import java.time.LocalDate;

public class Student implements Comparable<Student>{

	private Integer id;
	
	private String name;
	
	private LocalDate birth;

	/**
	 * 
	 */
	public Student() {
	}

	/**
	 * @param name
	 * @param birth
	 */
	public Student(String name, LocalDate birth) {
		this.name = name;
		this.birth = birth;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the birth
	 */
	public LocalDate getBirth() {
		return birth;
	}

	/**
	 * @param birth the birth to set
	 */
	public void setBirth(LocalDate birth) {
		this.birth = birth;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Student [id=").append(id).append(", name=").append(name).append(", birth=").append(birth)
				.append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public int compareTo(Student o) {
		System.out.println("--- 调用了 Student类的 compareTo方法...");
		//
		// if(this.name.compareTo(o.name) == 0) {
		if(this.name.equals(o.name)) {
			//如果名字相同，要进一步比较 birth
			return this.birth.compareTo(o.birth);
		}
		//名字不相同，则直接比较名字
		return this.name.compareTo(o.name);
	}
	
	
}
